package com.ruoyi.slope.ai.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slope.ai.domain.SlopeAiModuleBinding;
import com.ruoyi.slope.ai.service.ISlopeAiModuleBindingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模块绑定关系Controller
 * 
 * @author ruoyi
 * @date 2025-09-05
 */
@RestController
@RequestMapping("/ai/modeuleBinding")
public class SlopeAiModuleBindingController extends BaseController
{
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeAiModuleBindingService slopeAiModuleBindingService;

    /**
     * 查询模块绑定关系列表
     */
    @PreAuthorize("@ss.hasPermi('ai:modeuleBinding:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeAiModuleBinding slopeAiModuleBinding)
    {
        startPage();
        List<SlopeAiModuleBinding> list = slopeAiModuleBindingService.selectSlopeAiModuleBindingList(slopeAiModuleBinding);
        return getDataTable(list);
    }

    /**
     * 导出模块绑定关系列表
     */
    @PreAuthorize("@ss.hasPermi('ai:modeuleBinding:export')")
    @Log(title = "模块绑定关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeAiModuleBinding slopeAiModuleBinding)
    {
        List<SlopeAiModuleBinding> list = slopeAiModuleBindingService.selectSlopeAiModuleBindingList(slopeAiModuleBinding);
        ExcelUtil<SlopeAiModuleBinding> util = new ExcelUtil<SlopeAiModuleBinding>(SlopeAiModuleBinding.class);
        String path = util.exportExcel(response, list, "模块绑定关系数据");
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

    /**
     * 获取模块绑定关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:modeuleBinding:query')")
    @GetMapping(value = "/{bindingId}")
    public AjaxResult getInfo(@PathVariable("bindingId") String bindingId)
    {
        return success(slopeAiModuleBindingService.selectSlopeAiModuleBindingByBindingId(bindingId));
    }

    /**
     * 新增模块绑定关系
     */
    @PreAuthorize("@ss.hasPermi('ai:modeuleBinding:add')")
    @Log(title = "模块绑定关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlopeAiModuleBinding slopeAiModuleBinding)
    {
        return toAjax(slopeAiModuleBindingService.insertSlopeAiModuleBinding(slopeAiModuleBinding));
    }

    /**
     * 修改模块绑定关系
     */
    @PreAuthorize("@ss.hasPermi('ai:modeuleBinding:edit')")
    @Log(title = "模块绑定关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlopeAiModuleBinding slopeAiModuleBinding)
    {
        return toAjax(slopeAiModuleBindingService.updateSlopeAiModuleBinding(slopeAiModuleBinding));
    }

    /**
     * 删除模块绑定关系
     */
    @PreAuthorize("@ss.hasPermi('ai:modeuleBinding:remove')")
    @Log(title = "模块绑定关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bindingIds}")
    public AjaxResult remove(@PathVariable String[] bindingIds)
    {
        return toAjax(slopeAiModuleBindingService.deleteSlopeAiModuleBindingByBindingIds(bindingIds));
    }
}
